package io.adrainty.algorithm.leetcode.normal;

import java.util.Deque;
import java.util.LinkedList;

/**
 * @author adrainty
 * @version v1.0.0
 * @since 2024/12/23 上午11:07
 */
public class Solution9 {

    private Solution9() {}

    public static void main(String[] args) {
        System.out.println(isPalindrome(121));
        System.out.println(isPalindrome(10));
    }

    public static boolean isPalindrome(int x) {
        if (x < 0) return false;
        if (x == 0) return true;
        Deque<Integer> deque = new LinkedList<>();
        while (x != 0) {
            deque.offerLast(x % 10);
            x /= 10;
        }
        while (!deque.isEmpty() && deque.size() >= 2) {
            Integer first = deque.pollFirst();
            Integer last = deque.pollLast();
            if (first != last) return false;
        }
        return true;
    }
}
